<?php
include 'DBconn.php';
class CountryMaster
{
    public function getAllCountries()
    {
        $result=mysql_query("select * from country_header where activestatus=1") or die(mysql_error());
        $res_arr=array();
        while($row=mysql_fetch_object($result))
        {
            $tmp=new VOCountryMaster();
            $tmp->serialnumber=(int)$row->serialnumber;
            $tmp->country_name=$row->country_name;
            $tmp->cre_userid_fk=(int)$row->cre_userid_fk;
            $tmp->cre_datetime=$row->cre_datetime;
            $tmp->activestatus=(boolean)$row->activestatus;
            $res_arr[]=$tmp;
        }
        mysql_free_result($result);
    return $res_arr;
    }
    public function addNewCountry($VObject)
    {
        $query="insert into country_header(country_name,cre_userid_fk,cre_datetime,activestatus)values('$VObject->country_name','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
        $s=mysql_query($query) or die(mysql_error());
        if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllCountries();
    }
    public function deleteCountry($VObject)
    {
        $query="update country_header set activestatus=0 where serialnumber=".$VObject->serialnumber;
        $s=mysql_query($query) or die(mysql_error());
        if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
       return $this->getAllCountries();
    }
    public function editCountry($VObject)
    {
        $query="update country_header set country_name='$VObject->country_name',cre_userid_fk='$VObject->cre_userid_fk',cre_datetime='$VObject->cre_datetime' where serialnumber=".$VObject->serialnumber;
        $s=mysql_query($query) or die(mysql_error());
        if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
       return $this->getAllCountries();
    }
}
class VOCountryMaster
{
    var $serialnumber;
    var $country_name;
    var $cre_userid_fk;
    var $cre_datetime;
    var $activestatus;
}
?>